{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/slide/index')}">Banner列表</a></li>
            <li class="layui-this">编辑Banner</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/slide/update')}" method="post">
                    {:token()}
                    <input type="hidden" name="id" value="{$slide.id}">
                    <div class="layui-form-item">
                        <label class="layui-form-label">Banner名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="Banner_name" value="{$slide.name}" placeholder="请输入Banner标题(限制12字)" class="layui-input">
                        </div>
                    </div>




                    <div class="layui-form-item">
                        <label class="layui-form-label">外部链接</label>
                        <div class="layui-input-block">
                            <input type="text" name="link" value="{$slide.link}"  placeholder="外部链接" class="layui-input">
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$slide.sort}" class="layui-input">
                        </div>
                    </div>



                    <div class="layui-form-item">
                        <label class="layui-form-label">显示设置</label>
                        <div class="layui-input-block">
                            {switch	name="slide.status"}
                            {case	value="0"}
                            <input type="radio" name="status" value="0" title="下线" checked="checked">
                            <input type="radio" name="status" value="1" title="上线">
                            {/case}
                            {case	value="1"}
                            <input type="radio" name="status" value="0" title="下线">
                            <input type="radio" name="status" value="1" title="上线" checked="checked">
                            {/case}
                            {default	/}
                            <input type="radio" name="status" value="0" title="下线" checked="checked">
                            <input type="radio" name="status" value="1" title="上线">
                            {/switch}

                        </div>
                    </div>


                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">Banner备注</label>
                        <div class="layui-input-block">
                            <textarea  name="remark" placeholder="请输入内容" class="layui-textarea">{$slide.remark}</textarea>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">Banner封面</label>
                        <div class="layui-input-block">
                            <input type="text" name="img_url" value="{$slide.image}"lay-verify="required" class="layui-input layui-input-inline" id="Cover_Ad" style="display: none;">
                            <input type="file" name="image" lay-type="images" class="layui-upload-file">
                            <div class="ad_index_img_box">
                                <img style="display: block; width: 92px;" src="{$slide.image}"/>
                            </div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/ueditor/ueditor.config.js"></script>
<script src="__JS__/ueditor/ueditor.all.min.js"></script>
{/block}
{block name="script"}
<script>

    $(function() {
        layui.upload({
            url: "/api/file_upload/upload",
            before: function(obj){
                _loadshow("正在上传");
            },
            success: function (data) {
                _loadhide();
                if (data.error === 0 && data.type === 'image') {
                    document.getElementById('Cover_Ad').value = data.url;
                    var _ad_index_img_box = $(".ad_index_img_box");//上传图片显示盒子
                    _ad_index_img_box.empty();
                    _ad_index_img_box.append(
                        '<img style="display: block; width: 92px;" src="' + data.url + '"/>'
                    );
                } else {
                    layer.msg(data.message);
                }
            }
        });

        $('.date').on('click', function () {
            laydate({
                elem: this
                ,format: 'YYYY-MM-DD hh:mm:ss'
                ,type: 'datetime'
            })
        });
    });

</script>
<script>
    layui.use('upload', function(){
        var $ = layui.jquery
                ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });  });
    </script>

{/block}